import tensorflow as tf


class TfNN:
    """
    没给变量命名
    """
    def __init__(self):
        initializer = tf.random_normal_initializer(mean=0.0, stddev=0.05, seed=42, dtype=tf.float64)
        self.w1 = tf.Variable(initializer(shape=(9, 128)), dtype=tf.float64)
        self.w2 = tf.Variable(initializer(shape=(128, 32)), dtype=tf.float64)
        self.w3 = tf.Variable(initializer(shape=(32, 1)), dtype=tf.float64)
        self.b1 = tf.Variable(0.2, dtype=tf.float64)
        self.b2 = tf.Variable(0.2, dtype=tf.float64)
        self.b3 = tf.Variable(0.2, dtype=tf.float64)

    def forward(self, input_x):
        out1 = tf.matmul(input_x, self.w1) + self.b1
        logit1 = tf.math.sigmoid(out1)
        out2 = tf.matmul(logit1, self.w2) + self.b2
        logit2 = tf.math.sigmoid(out2)
        out3 = tf.matmul(logit2, self.w3) + self.b3
        return tf.math.sigmoid(out3)


class NNModel:
    """
    给变量命名了
    """
    def __init__(self):
        initializer = tf.random_normal_initializer(mean=0.0, stddev=0.1, seed=42, dtype=tf.float64)
        self.w1 = tf.Variable(initializer(shape=(9, 16)), dtype=tf.float64, name="w1")
        self.w2 = tf.Variable(initializer(shape=(16, 8)), dtype=tf.float64, name="w2")
        self.w3 = tf.Variable(initializer(shape=(8, 1)), dtype=tf.float64, name="w3")
        self.b1 = tf.Variable(0.2, dtype=tf.float64, name="b1")
        self.b2 = tf.Variable(0.3, dtype=tf.float64, name="b2")
        self.b3 = tf.Variable(0.25, dtype=tf.float64, name="b3")

    def forward(self, input_x):
        out1 = tf.matmul(input_x, self.w1) + self.b1
        logit1 = tf.math.sigmoid(out1, name='logit1')
        out2 = tf.matmul(logit1, self.w2) + self.b2
        logit2 = tf.math.sigmoid(out2, name='logit1')
        out3 = tf.matmul(logit2, self.w3) + self.b3
        return tf.math.sigmoid(out3)
